package com.tjsinfo.tjsoa.useseal.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.useseal.bo.ITUseSealSealBO;
import com.tjsinfo.tjsoa.useseal.bo.ITUseSealSealFileBO;
import com.tjsinfo.tjsoa.useseal.bo.ITUseSealSealOpeBO;
import com.tjsinfo.tjsoa.useseal.vo.TUseSealSealFile;

public class SealDelAction extends Action {
	private ITUseSealSealBO sealBo;
	private ITUseSealSealOpeBO sealOpeBo;
	private ITUseSealSealFileBO sealFileBo;
	
	public void setSealFileBo(ITUseSealSealFileBO sealFileBo) {
		this.sealFileBo = sealFileBo;
	}
	public void setSealBo(ITUseSealSealBO sealBo) {
		this.sealBo = sealBo;
	}
	public void setSealOpeBo(ITUseSealSealOpeBO sealOpeBo) {
		this.sealOpeBo = sealOpeBo;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {	
			String id = request.getParameter("id");
			Integer sealMark = Integer.parseInt(request.getParameter("sealMark"));
			String linkurl = null;
			String message = null;
			switch (sealMark) {
			case 0:
				linkurl = "useSeal/gen/genList.jsp";
				message = "useSeal.genDel.message";
				break;
			case 1:
				linkurl = "useSeal/imp/impList.jsp";
				message = "useSeal.impDel.message";
				break;
			case 2:
				linkurl = "useSeal/name/nameList.jsp";
				message = "useSeal.nameDel.message";
				break;				
			}

			sealBo.delete(id);
			sealOpeBo.deleteA(id);
			
			List<TUseSealSealFile> list1 =  sealFileBo.selectSealId(id);
			for(TUseSealSealFile tussf:list1){
				String strdos = "cmd /c del \""+tussf.getToFilePath()+"\"";
				Process process;		
				process = Runtime.getRuntime().exec(strdos);
				process.waitFor();
			}
			
			sealFileBo.deleteA(id);
			request.setAttribute("linkurl", linkurl);
			request.setAttribute("message", message);				
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
